package tools;

import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.util.Log;

/**
 * Created by ThinkPad on 2017/1/13.
 */
public class PermissionManger {

    public static final int PERMISSIONS = 11;

    /**
     *
     * @param activity
     * @return
     */
    public static boolean getPermission(Activity activity, String[] permissions ){
        if (Build.VERSION.SDK_INT >= 23) {
            for(String permission:permissions) {
                if (ContextCompat.checkSelfPermission(activity, permission) != PackageManager.PERMISSION_GRANTED) {
                    Log.e("getdata", "API-23,PERMISSION HAVE NOT");
                    ActivityCompat.requestPermissions(activity, permissions,
                            PERMISSIONS);
                    return false;
                }
            }
            Log.e("getdata","API-23,PERMISSION HAVE");
            return true;

        }else{
            Log.e("getdata","SMALL-API-23");
            return true;
        }

    }

}
